package com.tarena.lbs.business.dao.mapper.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tarena.lbs.business.dao.mapper.BusinessMapper;
import com.tarena.lbs.business.dao.repository.BusinessRepository;
import com.tarena.lbs.business.pojo.po.BusinessPO;
import com.tarena.lbs.business.pojo.po.StorePO;
import com.tarena.lbs.business.pojo.query.BusinessQuery;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
@DubboService
public class BusinessRepositoryImpl implements BusinessRepository {
    @Autowired
    private BusinessMapper businessMapper;
    
    @Override
    public void save(BusinessPO businessPO) {
        businessMapper.save(businessPO);
    }

    @Override
    public BusinessPO getBusinessById(Integer id) {
        return businessMapper.getBusinessById(id);
    }

    @Override
    public BusinessPO getBusinessByPhone(String phone) {
        return businessMapper.getBusinessByPhone(phone);
    }

    @Override
    public List<BusinessPO> getBusinesses() {
        return businessMapper.getBusinesses();
    }

    @Override
    public PageInfo<BusinessPO> pagesList(BusinessQuery query) {
        // 启动分页
        PageHelper.startPage(query.getPageNo(), query.getPageSize());
        // 执行查询
        List<BusinessPO> businesses = businessMapper.getAllBusinesses(query);
        // 封装分页信息
        return new PageInfo<>(businesses);
    }

    @Override
    public List<StorePO> getStoresByBusinessId(Integer businessId) {
        return businessMapper.getStoresByBusinessId(businessId);
    }
}
